#include <stm32f10x.h>
#include <stdbool.h>
#include <stdio.h>

void delay_ms(unsigned int ms)
{
    int n = 0;
    while (ms--)
    {
        for (n = 0; n < 1000; n++)
            ;
    }
}

static unsigned char graph[] = {0x3C, 0x42, 0xA5, 0xDB, 0x81, 0xA5, 0x5A, 0x3C};

void show_matrix(unsigned char graph[])
{
    int row = 0x7F;
    int i = 0;
    for (i = 0; i < 8; i++)
    {

        GPIO_Write(GPIOA, row);
        GPIO_Write(GPIOB, graph[i]);
        row >>= 1;
        row |= 0x80;
        delay_ms(5);
        GPIO_Write(GPIOA, 0xFF);
    }
}

void init_gpio_a_b()
{
    GPIO_InitTypeDef def;

    def.GPIO_Mode = GPIO_Mode_Out_PP;
    def.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
    def.GPIO_Speed = GPIO_Speed_50MHz;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);

    GPIO_Init(GPIOA, &def);

    GPIO_Init(GPIOB, &def);
}

int main()
{

    init_gpio_a_b();
    while (true)
    {
        show_matrix(graph);
    }

    return 0;
}
